/**
 * Created by Administrator on 2014/11/20 0020.
 */
define(["dojo/_base/declare",
    "dojo/_base/array",
    "dojo/_base/lang",
    "dijit/registry",
    "dojo/topic",
    "dojo/query",
    "dojo/on",
    "dojo/dom-style",
    "dijit/_WidgetBase",
    "dijit/_TemplatedMixin",
    "dzdtApp/dzdtAppConfig",
    "dojo/text!./bannerTemplate.html",
    "xstyle/css!./banner.css"
], function (declare, array, lang, registry, topic, query, on, domStyle, _WidgetBase, _TemplatedMixin, dzdtAppConfig, template) {
    return declare([_WidgetBase, _TemplatedMixin], {
        templateString: template,
        navConfig: {
            "公路专题": {
                href: "dzdtApp/layout/glzt/navQueryStatistics.html",
                cpLeftPublishConfig: {
                    headMenu: "公路专题",
                    QueryStatistics: "查询",
                    text: "默认"
                }
            },
            "运管专题": {
                href: "dzdtApp/layout/ygzt/ygNav.html",
                cpLeftPublishConfig: {
                    headMenu: "运管专题",
                    QueryStatistics: "查询",
                    text: "默认"
                }
            },
            "航运专题": {
                href: "dzdtApp/layout/ghzt/navQueryStatistics.html",
                cpLeftPublishConfig: {
                    headMenu: "航运专题",
                    QueryStatistics: "查询",
                    text: "默认"
                }
            },
            "路政专题": {
                href: "dzdtApp/layout/lzzt/lzNav.html",
                cpLeftPublishConfig: {
                    headMenu: "路政专题",
                    QueryStatistics: "查询",
                    text: "默认"
                }
            },
            "数据分析": {
                href: "dzdtApp/layout/dataAnalyze/sjfx.html",
                cpLeftPublishConfig: {
                    headMenu: "数据分析",
                    QueryStatistics: "查询",
                    text: "默认"
                }
            }
        },
        constructor: function () {
            dzdtAppConfig.cpLeftPublishConfig = this.navConfig["公路专题"].cpLeftPublishConfig;
        },
        postCreate: function () {
            this.inherited(arguments);
            var nodeList = query(".myNavClass", this.widgetContent);
            array.forEach(nodeList, lang.hitch(this, function (item) {
                on(item, "click", lang.hitch(this, function (evt) {
                    var menuText = evt.target.textContent;
                    var hrefConfig = this.navConfig[menuText];
                    var href = require.toUrl(hrefConfig.href);
                    var myCpLeftHead = registry.byId("myCpLeftHead");
                    if (myCpLeftHead) {
                        myCpLeftHead.set("href", require.toUrl(href));
                        dzdtAppConfig.cpLeftPublishConfig = hrefConfig.cpLeftPublishConfig;
                        topic.publish("leftPanelNavRequest", hrefConfig.cpLeftPublishConfig);
                    }
                }));
            }));
            on.once(this.widgetContent, "mousemove", lang.hitch(this, function () {
                this.hightLight(100);
            }));
        },
        startup: function () {
            this.inherited(arguments);
        },
        hightLight: function (con) {
            var count = $('#nav').find('li').length;
            $('.banner-nav').width(count * 120);
            con = typeof con === 'number' ? con : 400;
            var $lis = $('#nav>li'), $h = $('#buoy'), hleft = '0';
            $lis.click(function () {
                $h.stop().animate({
                    'left': $(this).offsetParent().context.offsetLeft
                }, con);
                hleft = $h.css('left');
            });
            $lis.hover(function () {
                $h.stop().animate({
                    'left': $(this).offsetParent().context.offsetLeft
                }, con);
            }, function () {
                $h.stop().animate({
                    'left': hleft
                }, con);
            })

        }
    });
});